// in einer Gruppenarbeit erstellt

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Artikel suchen</title>
<style type="text/css">
td {}
.start{vertical-align:top}
.name{vertical-align:top}
</style>
</head>
<body>
<table border="0" width="100%">
  <colgroup>
    <col width="62*">
    <col width="2*">
    <col width="1*">  
  </colgroup>
  <tr>
    <td class="name" align="left">Hallo <a href="profilverkaeufer.jsp">Name</a></td>
    <td align="center"><b><h2>iVerkauf</h2></b></td>
    <td class="start" align="right"><a href="index.jsp">Startseite</a></td>
  </tr>
</table>
<br>
<div>
<center><b>Suche</b>
<form action="Suchergebnis.jsp">
  <center>
  <p><input name="Suchfeld" type="text" size="60" maxlength="60"></p>
  </center>
</form>
<table border="0" align="center">
 <tr>
   <td>
   
</div>
<br>
<div>
<center>Sortieren nach: 
<select name="kategorie">
 <option value="name">Name</option>
 <option value="preis">Preis</option>
 <option value="gebote">Gebote</option>
 <option value="dauer">Dauer</option>	
</center>
</select>
</div>
<%@ page import="java.sql.*" isThreadSafe="false" %>
<br>
<br>
<center>
<%
  String sDbDrv = "oracle.jdbc.driver.OracleDriver";
  String sDbUrl = "jdbc:oracle:thin:a0925981/thekingmani@oracle-lab.cs.univie.ac.at:1521:lab";
  String sTable = "Artikel";
 	String eingabe= request.getParameter("Suchfeld");
 	String sSql2= " where lower(Bezeichnung) LIKE lower('" + eingabe + "%')";
  String sSql   = "Select Bezeichnung,Kategorie,Preis,Dauer FROM " + sTable  ;    
 
    Connection cn = null;
    Statement  st = null;
    ResultSet  rs = null;
    try {
      Class.forName( sDbDrv );
      cn = DriverManager.getConnection( sDbUrl);
      st = cn.createStatement();
      if(eingabe==null){
      rs = st.executeQuery( sSql );
      }
      else {
    	  sSql = sSql + sSql2;
    	  rs = st.executeQuery( sSql);
    	  
      }
      ResultSetMetaData rsmd = rs.getMetaData();
      int n = rsmd.getColumnCount();
      out.println( "<table border=30 cellspacing=5><tr>" );
      for( int i=1; i<=n; i++ )    
        out.println( "<th>" + rsmd.getColumnName( i ) + "</th>" );
      while( rs.next() )
      {
        out.println( "</tr><tr>" );
        for( int i=1; i<=n; i++ )  
          out.println( "<td>" + rs.getString( i ) + "</td>" );
      }
      out.println( "</tr></table>" );
    } finally {
      try { if( null != rs ) rs.close(); } catch( Exception ex ) {/*ok*/}
      try { if( null != st ) st.close(); } catch( Exception ex ) {/*ok*/}
      try { if( null != cn ) cn.close(); } catch( Exception ex ) {/*ok*/}
    }
 
%>
</center>
</body>
</html>